# blip_test.py
# Contains tests for the test module. 
#
# Copyright Notice:
#
# Copyright 2010 Nathanael Abbotts (nat.abbotts@gmail.com),
# 
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# About the Project:
#
#    This code is part of an ongoing project to fully emulate all the processes
#    of a Wave server. It is fully extensible, and can be used for a variety of
#    purposes, including testing, use as a client library, and many others.
#
#    The latest source code can be found at http://wave-emulator.googlecode.com,
#    along with links to or code for any official extensions, and a full wiki
#    explaining all code functions & best uses, and an issue tracker & feature 
#    request process.


import blip
__version__ = blip.__version__ + 'tests'
__doc__ = """Tests the blip module. Call 'main()' to run all tests."""
print "Version of blip: ", blip.__version__
print "Version of tests: ", __version__

tests_failed = []
def pr(x):
    """Print a BlipDocument object and it's rotation."""
    print x
    print 'rot x', x.rotation, 'len annotations', len(x.annotations)
def insert_characters():
    x = blip.BlipDocument()
    pr(x)
    x.insert_characters('Ths a rather interesting sentance.')
    pr(x)
    x.retain(2)
    pr(x)
    x.insert_characters('i')
    pr(x)
    x.retain(2)
    pr(x)
    x.insert_characters('is ')
    x.complete()
    print x
    if str(x) == "This is a rather interesting sentance.":
        print "Test \"INSERT CHARACTERS\" Succeeded"
        return ''
    else:
        print "Test \"INSERT CHARACTERS\" Failed"
        return "INSERT CHARACTERS"
    
def delete_characters_1():
    x = blip.BlipDocument()
    x.insert_characters('123456789')
    pr(x)
    x.delete(1)
    pr(x)
    x.retain(1)
    pr(x)
    x.delete(1)
    pr(x)
    x.retain(1)
    pr(x)
    x.delete(1)
    pr(x)
    x.retain(1)
    pr(x)
    x.delete(1)
    pr(x)
    x.retain(1)
    pr(x)
    x.delete(1)
    pr(x)
    x.complete()
    pr(x)
    if str(x) == "2468":
        print "Test DELETE CHARACTERS (1) Succeeded"
        return ''
    else:
        print "Test DELETE CHARACTERS (1) Failed"
        return "DELETE CHARACTERS (1)"
    
def delete_characters_2():
    x = blip.BlipDocument()
    x.insert_characters("Thiis is a sent!!!ance which contains  errors.")
    pr(x)
    x.retain(2)
    pr(x)
    x.delete(1)
    pr(x)
    x.retain(12)
    pr(x)
    x.delete(3)
    pr(x)
    x.complete()
    pr(x)
    if str(x) = "This is a sentance which contains errors.":
        print "Test DELETE CHARACTERS (2) Succeeded"
        return ''
    else:
        print "Test DELETE CHARACTERS (2) Failed"
        return "DELETE CHARACTERS (2)"
    
def main():
    tests_failed.append(insert_characters())
    tests_failed.append(delete_characters_1())
    tests_failed.append(delete_characters_2())
    print "Tests Failed:"
    for i in tests_failed:
        print "\t", i
    else:
        print "No further tests failed"
if __name__ == '__main__':
    main()
